<?php
namespace app\log\controller;
use think\Exception;
use think\Request;
use app\common\controller\Common;
class Operlog extends Common
{
	protected $model = null;
	protected $keyword_search = ['admin.admin_sn','admin.nkname','ol.event','ol.content'];
	protected $order = 'ol.addtime desc';
	protected $oper_type = ['【添加】','【编辑】','【删除】','【登录】','【退出】','【返库】'];

	public function _initialize()
	{
		parent::_initialize();
		$this->model = new \app\log\model\OperLog;
	}
	/**
	* 操作日志
	*/
	public function index()
	{
		if(Request()->isGet()){
			if(Request()->isAjax()){
				$data = Request()->param('');
				return $this->getList($data);
			}
			/*@操作者*/
			$admin = $this->model->getAdmin();
			$this->assign('admin',$admin);
			/*@操作类型*/
			$this->assign('oper_type',$this->oper_type);
			return $this->fetch('');
		}
	}
	/**********************************************************************************************************/
	/*********************************************** 私有 *****************************************************/
	/*********************************************************************************************************/
	/**
	* 数据处理
	*/
	protected function handleList($data)
	{
		$where = [];
		/*@登录者*/
		switch(session('admin.admin_type')){
			case 1: $where['ol.shop_id'] = session('admin.shop_id');break;//店长
			case 2:
			case 3: 
			$where['ol.admin_id'] = session('admin.admin_id');break;//营业员
		}
		/*@操作者*/
		if(isset($data['admin_id']) && $data['admin_id'] != ''){
			$where['ol.admin_id'] = $data['admin_id'];
		}
		/*@操作类型*/
		if(isset($data['event']) && $data['event'] != ''){
			$where['ol.event'] = $data['event'];
		}
		/*@时间*/
		$cusTime = $this->cusTime($data);
		if($cusTime === false) return false;
		if($cusTime){
			$where['ol.addtime'] = $cusTime;
		}
		return $where;
	}
}